package com.sc.VenusQueryBeta.ui.activites;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hengjun.kingstar.sdk.adapter.FragmentAdapter;
import com.hengjun.kingstar.sdk.base.BasePresenter;
import com.hengjun.kingstar.sdk.base.activity.BaseMVPCompatActivity;
import com.hengjun.kingstar.sdk.utils.LogUtils;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.constant.Constants;
import com.sc.VenusQueryBeta.constant.TabFragmentIndexHotel;
import com.sc.VenusQueryBeta.contract.hotel.tabs.OverSeaContract;
import com.sc.VenusQueryBeta.model.bean.home.OverSeasBean;
import com.sc.VenusQueryBeta.model.bean.home.VipListBean;
import com.sc.VenusQueryBeta.presenter.hotel.tabs.OverSeaPresenter;
import com.sc.VenusQueryBeta.ui.fragments.hotel.child.tabs.KaiXuanFragment;
import com.sc.VenusQueryBeta.ui.fragments.hotel.child.tabs.OverSeaFragment;
import com.sc.VenusQueryBeta.ui.fragments.hotel.child.tabs.RecreationFragment;
import com.sc.VenusQueryBeta.ui.fragments.hotel.child.tabs.VisaFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class OverSeasActivity extends BaseMVPCompatActivity<OverSeaContract.OverSeaPresenter> implements OverSeaContract.IOverSeaView {

    @BindView(R.id.about_hotel_back)
    ImageButton aboutHotelBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tl_hotel_tabs)
    TabLayout tlHotelTabs;
//    @BindView(R.id.app_bar)
//    AppBarLayout appBar;
    @BindView(R.id.vp_hotel_fragment)
    ViewPager vpHotelFragment;
    @BindView(R.id.hotel_container)
    CoordinatorLayout hotelContainer;
    private List<Fragment> fragments;
    String[] tabs = null;
    private VipListBean.DataBean.ClubListBean listBean;
    private OverSeasBean moverSeasBean1;

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_over_seas;
    }

    @Override
    protected void initData() {
        super.initData();
        tabs = new String[]{getString(R.string.guibinting), getString(R.string.entertainment), getString(R.string.visa)};
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            listBean = (VipListBean.DataBean.ClubListBean) extras.getSerializable(Constants.VIP_CLUB_LIST);
            tvTitle.setText(listBean.getClubName());
            if (listBean != null) {
                tabs[0] = listBean.getClubName();
                showProgressDialog("正在加載");
                mPresenter.getOversea(listBean.getVipClubId());

            }
//            ToastUtils.showToast("msg=" + listBean.getClubName());
        } else {
//            ToastUtils.showToast("msg=null" );
        }


    }


    @OnClick(R.id.about_hotel_back)
    public void onViewClicked() {
        finish();
    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return OverSeaPresenter.newInstance();
    }


    @Override
    public void showOverseaDataSuccess(OverSeasBean overSeasBean) {
        moverSeasBean1 = overSeasBean;
        LogUtils.e("asnasdjha"+moverSeasBean1.getData().getCreateTime());
        hideProgressDialog();

        fragments = new ArrayList<>();
        for (int i = 0; i < tabs.length; i++) {
            tlHotelTabs.addTab(tlHotelTabs.newTab().setText(tabs[i]));
            switch (i) {
                case TabFragmentIndexHotel.TAB_KAIXUANMMEN_INDEX: //凯旋门
//                    fragments.add(KaiXuanFragment.newInstance());
                    OverSeaFragment overSeaFragment1 = OverSeaFragment.newInstance();
                    Bundle bundle = new Bundle();
                    bundle.putSerializable(Constants.VIP_CLUB_LIST1, moverSeasBean1);
                    overSeaFragment1.setArguments(bundle);
                    fragments.add(overSeaFragment1);
                    break;
                case TabFragmentIndexHotel.TAB_HOTELDINING_INDEX: //酒店餐厅
//                    fragments.add(HotelDiningFragment.newInstance());
                    RecreationFragment recreationFragment = RecreationFragment.newInstance();
                    Bundle bundle1 = new Bundle();
                    bundle1.putSerializable(Constants.VIP_CLUB_LIST2, moverSeasBean1);
                    recreationFragment.setArguments(bundle1);
                    fragments.add(recreationFragment);
                    break;
                case TabFragmentIndexHotel.TAB_PRICE_INDEX: //酒店价格
//                    fragments.add(PriceFragment.newInstance());
                    VisaFragment visaFragment = VisaFragment.newInstance();
                    Bundle bundle2 = new Bundle();
                    bundle2.putSerializable(Constants.VIP_CLUB_LIST3, moverSeasBean1);
                    visaFragment.setArguments(bundle2);
                    fragments.add(visaFragment);
                    break;
                default: //默认凯旋门
                    fragments.add(KaiXuanFragment.newInstance());
                    break;
            }
        }
        vpHotelFragment.setAdapter(new FragmentAdapter(getSupportFragmentManager(), fragments));
        vpHotelFragment.setCurrentItem(TabFragmentIndexHotel.TAB_KAIXUANMMEN_INDEX);
        //要设置到viewpager.setAdapter后才起作用
        tlHotelTabs.setupWithViewPager(vpHotelFragment);
        tlHotelTabs.setVerticalScrollbarPosition(TabFragmentIndexHotel.TAB_KAIXUANMMEN_INDEX);
        //tlTabs.setupWithViewPager方法内部会remove所有的tabs，这里重新设置一遍tabs的text，否则tabs的text不显示
        for (int i = 0; i < tabs.length; i++) {
            tlHotelTabs.getTabAt(i).setText(tabs[i]);
        }
    }

    @Override
    public void showNetworkError() {
        hideProgressDialog();
    }

}
